package com.mc2.docapp.disabilityassessmenttool.LowerLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_llmp_hip extends RealmObject {
    private LLCustDataType flexion = new LLCustDataType();
    private LLCustDataType extension = new LLCustDataType();
    private LLCustDataType internal_rotation = new LLCustDataType();
    private LLCustDataType external_rotation = new LLCustDataType();
    private LLCustDataType adduction = new LLCustDataType();
    private LLCustDataType abduction = new LLCustDataType();
    private LLInnerCalculations inner_calculations = new LLInnerCalculations();

    public void calc(C_llmp_hip c_llca_hip) {
        double a = c_llca_hip.getFlexion().getActual_right();
        double b = c_llca_hip.getExtension().getActual_right();
        double c = c_llca_hip.getInternal_rotation().getActual_right();
        double d = c_llca_hip.getExternal_rotation().getActual_right();
        double e = c_llca_hip.getAdduction().getActual_right();
        double f = c_llca_hip.getAbduction().getActual_right();

        double pa = perc(a, c_llca_hip.getFlexion().getNormal());
        double pb = perc(b, c_llca_hip.getExtension().getNormal());
        double pc = perc(c, c_llca_hip.getInternal_rotation().getNormal());
        double pd = perc(d, c_llca_hip.getExternal_rotation().getNormal());
        double pe = perc(e, c_llca_hip.getAdduction().getNormal());
        double pf = perc(f, c_llca_hip.getAbduction().getNormal());

        double x = (pa + pb + pc + pd + pe +pf ) / 6.0;

        c_llca_hip.getFlexion().setPerc_loss_right(pa);
        c_llca_hip.getExtension().setPerc_loss_right(pb);
        c_llca_hip.getInternal_rotation().setPerc_loss_right(pc);
        c_llca_hip.getExternal_rotation().setPerc_loss_right(pd);
        c_llca_hip.getAdduction().setPerc_loss_right(pe);
        c_llca_hip.getAbduction().setPerc_loss_right(pf);

        //LEFT CALCULATIONS

        a = c_llca_hip.getFlexion().getActual_left();
        b = c_llca_hip.getExtension().getActual_left();
        c = c_llca_hip.getInternal_rotation().getActual_left();
        d = c_llca_hip.getExternal_rotation().getActual_left();
        e = c_llca_hip.getAdduction().getActual_left();
        f = c_llca_hip.getAbduction().getActual_left();

        pa = perc(a, c_llca_hip.getFlexion().getNormal());
        pb = perc(b, c_llca_hip.getExtension().getNormal());
        pc = perc(c, c_llca_hip.getInternal_rotation().getNormal());
        pd = perc(d, c_llca_hip.getExternal_rotation().getNormal());
        pe = perc(e, c_llca_hip.getAdduction().getNormal());
        pf = perc(f, c_llca_hip.getAbduction().getNormal());


        double y = (pa + pb + pc + pd + pe + pf) / 6.0;

        c_llca_hip.getFlexion().setPerc_loss_left(pa);
        c_llca_hip.getExtension().setPerc_loss_left(pb);
        c_llca_hip.getInternal_rotation().setPerc_loss_left(pc);
        c_llca_hip.getExternal_rotation().setPerc_loss_left(pd);
        c_llca_hip.getAdduction().setPerc_loss_left(pe);
        c_llca_hip.getAbduction().setPerc_loss_left(pf);
        c_llca_hip.setInner_calculations(new LLInnerCalculations(
                x,
                y,
                x * 0.3,
                y * 0.3
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
